﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using Celeriq.Utilities;

namespace Celeriq.Utilities
{
	public class ConfigurationSettings
	{
		private static ConfigurationSettings _instance = null;

		private ConfigurationSettings()
		{
			Initialize();
		}

		private void Initialize()
		{
			try
			{
				//HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Widgetsphere\Celeriq
				var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Widgetsphere\Celeriq");
				if (key == null)
				{
					throw new Exception("Celeriq has not been properly installed on this machine. Error 0x1980");
				}

				this.DataPath = (string)key.GetValue("DataPath");
				this.InstallPath = (string)key.GetValue("InstallPath");
			}
			catch (Exception ex)
			{
				Logger.LogError(ex);
				throw new Exception("Celeriq has not been properly installed on this machine. Error 0x1981");
			}
		}

		static ConfigurationSettings()
		{
		}

		public static ConfigurationSettings GetInstance()
		{
			if (_instance == null)
			{
				_instance = new ConfigurationSettings();
			}
			return _instance;
		}

		public static string GetUserFile()
		{
			return Path.Combine(Environment.SystemDirectory, "tere.kasutajad");
		}

		public static string GetKeyFile()
		{
			return Path.Combine(Environment.SystemDirectory, SecurityHelper.GetMachineId() + ".cqbin");
		}


		public string DataPath { get; private set; }
		public string InstallPath { get; private set; }

	}
}
